package com.ydt.dockingclients.utils;

import cn.hutool.crypto.digest.MD5;

import java.util.*;

public class SignUtils {
    // 签名
    public static String makeSign(String appKey, String appSecret, String data, long timestamp) {
        Map<String, String> dataMap = new HashMap<>();
        dataMap.put("appKey", appKey);
        dataMap.put("appSecret", appSecret);
        dataMap.put("data", data);
        dataMap.put("timestamp", String.valueOf(timestamp));
        List<String> keys = new ArrayList<>(dataMap.keySet());
        Collections.sort(keys);
        List<String> dataArr = new ArrayList<>();
        for (String key : keys) {
            String value = dataMap.get(key);
            dataArr.add(key + "=" + value);
        }
        String str = String.join("&", dataArr);
        return MD5.create().digestHex(str).toUpperCase();
    }
}
